package cn.sfa.service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.sfa.common.utils.CommonUtil;

@Service
@Transactional
public class CommonService {
	
	@Autowired
	NamedParameterJdbcTemplate jdbcTemplate;
	/**
	 * 查询供应商
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public  List getAllProvider()
	{
		String sql = "select providerid,providerabbr from provider t where t.providerstatus=\'PROVIDERSTATUS_1\' Order By VIEWSEQ";
		List providers=new ArrayList();
		providers=jdbcTemplate.queryForList(sql, new HashMap());
		return providers;
	}
	
	/**
	 * 获取下级代理人
	 * @param AgentID
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public  List getAgentAndUpAgentList(String AgentID)
	{
		String sql = "SELECT AGB.AGENTID,AGB.AGENTCODE,AGB.AGENTNAME FROM AGENTBROKER AGB WHERE AGB.AGENTID=:I_AGENTID OR AGB.RECOMMENDAGENTID=:I_AGENTID ";
		Map<String, Object> paramMap = new HashMap<String, Object>();
		paramMap.put("I_AGENTID", CommonUtil.jugeAndFixNull(AgentID));
		List AgentList=new ArrayList();
		AgentList=jdbcTemplate.queryForList(sql,paramMap);
		return AgentList;
	}
}
